var BASE = BASE||{};
BASE.USERCHARGE = (function () {
    var  $giftList = $('#giftList');

    /*获取心意价格*/
    BASE.COMMON.getGoodsPrice(7,function (res) {
        $giftList.html(template('giftList_tpl',{data:res}));
        if(res.length>0){
            var price = res[0].price;
            $giftList.data('sys_product_id',res[0].id);
            $giftList.data('price',price);
            if(price<0){
                $('#input-custom').show();
            }else {
                $('#input-custom').hide();
            }
        }
    });
    /*心意选择*/
    $giftList.on('click','li',function () {
        $(this).addClass('checked').siblings().removeClass('checked');
        var price = $(this).data('price');
        $giftList.data('price',price);
        $giftList.data('sys_product_id', $(this).data('id'));
        if(price<0){
            $('#input-custom').show();
        }else {
            $('#input-custom').hide();
        }
    });

    /*充值*/
    function charge(obj) {
        $(obj).attr('disabled',true);
        var sendData = {
            sysProductId:$giftList.data('sys_product_id'),
        };
        if($giftList.data('price')<0){
            sendData.price = $('#price').val();
        }
        BASE.postHttp('/device/order/recharge/buy',sendData,function (res) {
            $(obj).attr('disabled',false);
            if(res.code!=200){
                BASE.clearpop(res.message);
                return;
            }
            location.href = '/userSubmitOrder.html?id='+res.data.id;
        })
    }

    return{
        charge:charge,
    }
})();
